import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 定义路由规则
const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')
  }, {
    path: '/',
    // name: 'layout', // 如果父路由有默认子路由，那他的name就没有意义，可以省略
    component: () => import('@/views/layout'),
    children: [{
      path: '', // 默认子路由，只能有一个，当访问/的时候，显示home组件
      name: 'home',
      component: () => import('@/views/home')
    },
    {
      path: '/qa',
      name: 'qa',
      component: () => import('@/views/qa')
    },
    {
      path: '/video',
      name: 'video',
      component: () => import('@/views/video')
    },
    {
      path: '/my',
      name: 'my',
      component: () => import('@/views/my')
    }, {
      path: '/search',
      name: 'search',
      component: () => import('@/views/search')
    }, {
      path: '/article/:articleId',
      name: 'article',
      component: () => import('@/views/article'),
      // 将路由动态参数映射到组件的 props 中，更推荐这种做法
      props: {
        articleId: {
          type: [Number, String],
          required: true
        }
      }
    }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
